#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/12/27 20:21
# @Author  : Sun
# @File    : modify_family_note.py
# @Software: PyCharm
import json

import requests

from common.mis_login import MisLogin
from common.read_yaml import ReadYaml
from common.write_log import WriteLog


class ModifyGrow:
    _URL = "https://mis.jjmatch.cn/oms/evt_v2/api//common/GrowValueQueryEdit/websvrrest_devtest_modify_evt_by_eid"
    _DATA = [
        {
            "p_eid": "60000767",
            "p_value": None,
            "p_userid": None
        }
    ]
    _HEADERS = {
        'authority': 'mis.jjmatch.cn',
        'pragma': 'no-cache',
        'cache-control': 'no-cache',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36',
        'content-type': 'application/json',
        'accept': '*/*',
        'origin': 'https://mis.jjmatch.cn',
        'sec-fetch-site': 'same-origin',
        'sec-fetch-mode': 'cors',
        'sec-fetch-dest': 'empty',
        'referer': 'https://mis.jjmatch.cn/oms/evt_v2/Views/EventGrowSearch.html?bID=9449',
        'accept-language': 'zh-CN,zh;q=0.9'
    }

    # _COOKIE = MisLogin().mis_login()
    # print(ReadYaml().read_yaml('./config/mis_cookie.yaml'))
    try:
        _COOKIE = dict(ReadYaml().read_yaml('./config/mis_cookie.yaml'))
    except TypeError:
        MisLogin().mis_login()
        _COOKIE = dict(ReadYaml().read_yaml('./config/mis_cookie.yaml'))
    # print(_COOKIE)

    def modify_grow(self, value: str = None, userid=None):
        WriteLog().write_log().info(self._COOKIE)
        self._DATA[0]['p_value'] = value
        self._DATA[0]['p_userid'] = userid
        print(value, userid)
        r = requests.request(
            data=json.dumps(
                self._DATA),
            method='POST',
            url=self._URL,
            headers=self._HEADERS,
            cookies=self._COOKIE)
        # print(r.json())
        result = json.dumps(r.json(), ensure_ascii=False, indent=4)
        WriteLog().write_log().info(r.json()['data']['rows'][0]['p_new_value'])
        return result


if __name__ == '__main__':
    ModifyGrow().modify_grow(value="1000", userid="106146479")
